package drawingObjects;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point;
import java.util.ArrayList;

public class FreeFormLine extends DrawingObject {

	private ArrayList<Point> points;
	public FreeFormLine() {
		super();
		points = new ArrayList<Point>();
	}
	
	@Override
	public void paintComponent(Graphics g){
		super.paintComponent(g);
		g.setColor(this.color);
		int i = 0;
		Point p2;
		for(Point p1 : points){
			if(i == points.size() - 1) break;
			p2 = points.get(i + 1);
			g.drawLine(p1.x, p1.y, p2.x, p2.y);
			i++;
		}
	}

	@Override
	public void start(Point p) {
		points.clear();
		points.add(p);
	}

	@Override
	public void step(Point p) {
		points.add(p);
	}
	
	public boolean commit(){
		return points.size() > 1;
	}

}
